package com.qf.application.config;

import com.qf.application.interceprot.UserTokenInterceptor;
import com.qf.application.interceprot.UserUrlInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    @Autowired
    private UserTokenInterceptor userTokenInterceptor;

    @Autowired
    private UserUrlInterceptor userUrlInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 添加登录的拦截器
        registry.addInterceptor(userTokenInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login")  // 登录的操作不需要拦截器
                .order(1); // 设置优先级，数值越小优先级越高

//        // 添加权限的拦截器
        registry.addInterceptor(userUrlInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/login")
                .order(2);
    }

//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry
//                .addMapping("/**")
//                .allowedMethods("GET", "POST", "DELETE", "PUT")
//                .allowedOrigins("*")
//                .allowedHeaders("*");
//    }


}
